package com.songshuai.webapi.baseapi.enumerations.sales.error;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public enum SopTypeError {

    ERROR_PARENT_TYPE_ID_NOT_EXIST(1,"父类型ID错误"),
    ERROR_PARENT_TYPE_NOT_SHOW(2,"上级分类状态为不显示时，下级分类状态必为不显示"),
    ERROR_TYPE_NAME_REPEAT(3,"分类名称重复"),
    ERROR_TYPE_EXIST_CHILD(4,"存在下级分类，请先删除下级分类"),
    ERROR_TYPE_EXIST_SOP(5,"分类有关联内容，请先删除关联内容");

    private int code;
    private String msg;

    SopTypeError(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define){
        try {
            return SopTypeError.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return 0;
        }
    }

    public static String getMsg(String define){
        try {
            return SopTypeError.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            log.error("undefined error code: {}", define);
            return "";
        }
    }

    public static String getMsg(Integer code){
        if(code==null||code<=0)
            return "";
        for(SopTypeError err : SopTypeError.values()){
            if(err.code==code){
                return err.msg;
            }
        }
        return "";
    }

    public int getCode(){
        return code;
    }

    public String getMsg(){
        return msg;
    }
}
